package edu.fim.core.service.impl;

import java.util.List;

import edu.fim.core.exception.ServiceException;
import edu.fim.core.service.FoodService;
import edu.fim.data.dao.DAO;
import edu.fim.data.dao.FoodDAO;
import edu.fim.data.dao.exception.DAOException;
import edu.fim.data.dao.factory.DAOFactory;
import edu.fim.presentation.model.bean.Consumer;
import edu.fim.presentation.model.bean.Food;

public class FoodServiceImpl implements FoodService {

	public List<Food> findAll() throws ServiceException {
		DAO<Food, Integer> dao = DAOFactory.getInstance().createFoodDao();
		try {
			return dao.findAll();
		}
		catch (DAOException e) {
			throw new ServiceException(e);
		}
	}
	
	public List<Food> findNonPreferences(Consumer consumer) {
		FoodDAO fDao = DAOFactory.getInstance().createFoodDao();
		List<Food> foods = fDao.findAll();
		for (Food food : consumer.getPreferences()) {
			foods.remove(food);
		}
		return foods;
	}
}